package com.wb.spring.boot.autoconfigure.http;

import com.wb.spring.boot.autoconfigure.annotation.ConditionalOnWbClientEnabled;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;


/**
 * @Author deeprado
 * @Date 2022/8/25 19:25
 */
@Slf4j
@ConditionalOnWbClientEnabled
@Configuration
@AutoConfigureAfter(value = {WbClientAutoConfiguration.class, WbOkHttpAutoConfiguration.class, WbHttpClientAutoConfiguration.class})
public class WbDefaultHttpAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder
                //设置连接超时时间
                .setConnectTimeout(Duration.ofSeconds(5000))
                //设置读取超时时间
                .setReadTimeout(Duration.ofSeconds(5000))
                //构建
                .build();
    }


}
